<template>
    <div class="system-quill-editor">
        <quill-editor
            class="ql-editor"
            ref="myQuillEditor" 
            :value="value"              
            :options="editorOption"            
            @ready="onEditorReady($event)"
            @change="onEditorChange($event)"
        >
        </quill-editor>
    </div>
</template>

<script>
import Quill from 'quill'
import imageResize from 'quill-image-resize-module'
Quill.register('modules/imageResize', imageResize)
import { addQuillTitle } from '@/common/utils/quill-title.js'

export default {
    name: 'systemQuillEditor',
    props: {
        value: {
            type: String
        }
    },
    data() {
        return {
            editorOption: {
                modules: {
                    imageResize: {
                        displayStyles: {
                            backgroundColor: 'black',
                            border: 'none',
                            color: 'white'
                        },
                        modules: ['Resize', 'DisplaySize', 'Toolbar']
                    },
                    toolbar: [
                        ['bold', 'italic', 'underline', 'strike'],
                        ['blockquote', 'code-block'],
                        [{ 'header': 1 }, { 'header': 2 }],
                        [{ 'list': 'ordered' }, { 'list': 'bullet' }],
                        [{ 'script': 'sub' }, { 'script': 'super' }],
                        [{ 'indent': '-1' }, { 'indent': '+1' }],
                        // [{ 'direction': 'rtl' }],
                        // [{ 'size': ['small', false, 'large', 'huge'] }],
                        // [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
                        // [{ 'font': [] }],
                        [{ 'color': [] }, { 'background': [] }],
                        [{ 'align': [] }],
                        // ['clean'],
                        ['link', 'image', 'video']
                    ]
                },
                placeholder: '请输入内容',
                theme: 'snow'
            }
        }
    },
    computed: {
        editor() {
            return this.$refs.myQuillEditor.quill
        }
    },
    mounted() {
        addQuillTitle()
    },
    methods: {
        onEditorReady() {
            console.log('editor ready!')
        },
        onEditorChange({ html, text }) {
            console.log('editor change!', html, text)
            this.$emit('input', html)
        },
        handleClearEditor() {
            this.$emit('input', '')
        }
    }
}
</script>

<style lang="less" scoped>
.system-quill-editor{
    // height:600px;
}
.system-quill-editor /deep/ .ql-editor {
    position: relative;
    padding: 0;
    line-height: 0;
    .ql-toolbar {
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        z-index: 99;
        border-radius: 4px 4px 0 0;
        border-color: #dcdee2;
        background-color: #fff;
    }
    .ql-formats:last-of-type {
        margin-right: 0;
    }
    .ql-container {
        min-height: 200px;
        max-height: 600px;
        border-radius: 0 0 4px 4px;
        border-color: #dcdee2;
        .ql-editor {
            height: 400px;;
            padding: 12px 8px;
            font-size: 14px;
            line-height: 1.5;
            &.ql-blank::before {
                color: #c5c8ce;
                font-style: normal;
                font-size: 14px;
            }
        }
    }
}
</style>
